﻿/////////////////////////////////////////////////////////////////
//File: BlogManager.cs
//Description: 此文件是根据facade模式和接口隔离原则创建的。各个子业务之间的关联在这里建立。 
//            
//Copyright© 2011 Moliu
//History:
//  2011-3-26 18:11:20    CodeSmith5.0.1    Original Version
//  2011-3-26 19:26:20    Moliu             1
//  2011-4-17 13:13:15    Moliu             2
//  2011-4-23 12:21:49    Moliu             3
//  2011-4-22 22:10:12    Moliu             4
/////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Security.Permissions;
using System.Transactions;

using MAF.Common;
using MAF.Common.Security;
using My.Blog.Domain.Entities;
using My.Blog.Domain.Interfaces;
using My.Blog.Business.Persistence;
using My.Blog.Business.Security;

namespace My.Blog.Business.Service
{
    public partial class CommentSvc : IComment
    {
        IComment _Comment = DaoFactory.Instance.CreateComment();

        #region 构造函数
        public CommentSvc() 
        {
        }
        #endregion
       
        #region IComment 成员
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public object CreateComment(Comment info )
        {
            //IComment _Comment = DaoFactory.Instance.CreateComment();

            info.DateCreated = DateTime.Now;
            object o = _Comment.CreateComment(info);

            IArticle art = DaoFactory.Instance.CreateArticle();
            art.IncreaseCommentAmount(info.ArticleId,1);  // 评论数+1
            return o;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public int UpdateComment(Comment info )
        {
            //IComment _Comment = DaoFactory.Instance.CreateComment();

            info.DateModified = DateTime.Now;
            return _Comment.UpdateComment(info);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="info">需要info.ArticleId进行统计字段更新</param>
        /// <returns></returns>
        public int DeleteComments(Comment info )
        {
            //IComment _Comment = DaoFactory.Instance.CreateComment();

            int i = _Comment.DeleteComments(info);

            IArticle art = DaoFactory.Instance.CreateArticle();
            art.IncreaseCommentAmount(info.ArticleId,-i); // 评论数-n
            return i;
        }
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public Comment ReadCommentById(Comment info )
        {
            //IComment _Comment = DaoFactory.Instance.CreateComment();
            return _Comment.ReadCommentById(info);
        }
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="info"></param>
        /// <param name="pageSize"></param>
        /// <param name="currentPage"></param>
        /// <returns></returns>
        public IList<Comment> ReadCommentsByConditions(Comment info, int pageSize, int currentPage )
        {
            //IComment _Comment = DaoFactory.Instance.CreateComment();

            PageInfo page = new PageInfo( pageSize,currentPage );
            page.RecordCount = _Comment.ReadCommentsCountByConditions(info);
            return _Comment.ReadCommentsByConditions(info,page.PageSize,page.CurrentPage);
        }
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public int ReadCommentsCountByConditions( Comment info )
        {
            //IComment _Comment = DaoFactory.Instance.CreateComment();
            return _Comment.ReadCommentsCountByConditions( info );
        }
        #endregion

        //================================
        // 上面是自动生成的代码,下面是手工编写的代码
        //================================ 
    }
}
